package com.li.jobs;

import com.li.utils.QiniuUtils;
import com.li.utils.RedisConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/*
定时清理垃圾图片
 */
public class CleanSetmealGarbageitPic {
    private static int count;
    @Autowired
    JedisPool jedisPool;

    //生成静态页面
    public void cleanImgJob(){
        //根据redis保存的二个set集合进行差值运算
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.getSetmealPicDbResources(), RedisConstant.getSetmealPicResources());

        if(sdiff.size()>0){
            for (String picName : sdiff) {
                //删除七牛云服务器上的图片
                QiniuUtils.deleteFileFromQiniu(picName);
            }
            //清空二个set集合
            jedisPool.getResource().del(RedisConstant.getSetmealPicDbResources());
            jedisPool.getResource().del(RedisConstant.getSetmealPicResources());
            System.out.println("垃圾图片清理成功!当前已清理"+(++count)+"次");
        }else{
            System.out.println("清理失败!当前无垃圾图片");
        }
    }

}
